package com.utf999.qiangmanger.service;

import java.io.Serializable;

import org.apache.log4j.Logger;

import com.utf999.qiangmanger.dao.IQiangDAO;
import com.utf999.qiangmanger.entity.AbstractEntity;

/**
 * 绑定了DAO层的抽象Abstarct服务层，
 * 该抽象服务接口集成了memcachedService服务，以便开发人员能够从memcached server获取所需要的数据
 * @author wenjie 
 * @param <T> 绑定的需要处理的实体类
 * @param <S> 绑定的匹配数据层
 */
public abstract class AbstractService <T extends AbstractEntity , S extends IQiangDAO<T>> implements IQiangService {
	
	protected final Logger logger = Logger.getLogger(getClass());
	
	/**
	 * 指定当前server所匹配的主要的DAO类
	 * @return
	 */
	protected abstract S getBaseDAO();
	
	/* (non-Javadoc)
	 * @see com.helome.springcore.service.IHelomeService#insert(com.helome.springcore.entity.AbstractEntity)
	 */
	@SuppressWarnings("unchecked")
	public void insert(AbstractEntity entity) {
		this.getBaseDAO().insert((T)entity);
	}
	
	/* (non-Javadoc)
	 * @see com.tuan800.im.usercenter.service.ITUANService#insertAndRefresh(com.tuan800.im.usercenter.entity.AbstractEntity)
	 */
	@SuppressWarnings("unchecked")
	public void insertAndRefresh(AbstractEntity entity) {
		this.getBaseDAO().insertAndRefresh((T)entity);
	}

	/* (non-Javadoc)
	 * @see com.helome.springcore.service.IHelomeService#update(com.helome.springcore.entity.AbstractEntity)
	 */
	@SuppressWarnings("unchecked")
	public void update(AbstractEntity entity) {
		this.getBaseDAO().update((T)entity);
	}
	
	/* (non-Javadoc)
	 * @see com.tuan800.im.usercenter.service.ITUANService#updateAndRefresh(com.tuan800.im.usercenter.entity.AbstractEntity)
	 */
	@SuppressWarnings("unchecked")
	public void updateAndRefresh(AbstractEntity entity) {
		this.getBaseDAO().updateAndRefresh((T)entity);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.tuan800.im.usercenter.service.ITUANService#saveOrUpdate(com.tuan800.im.usercenter.entity.AbstractEntity)
	 */
	@SuppressWarnings("unchecked")
	public void saveOrUpdate(AbstractEntity entity) {
		this.getBaseDAO().saveOrUpdate((T)entity);
	}

	/* (non-Javadoc)
	 * @see com.helome.springcore.service.IHelomeService#getEntity(java.io.Serializable)
	 */
	public T getEntity(Serializable id) {
		return this.getBaseDAO().getEntity(id);
	}

	/* (non-Javadoc)
	 * @see com.helome.springcore.service.IHelomeService#delete(java.io.Serializable)
	 */
	public void delete(Serializable id) {
		this.getBaseDAO().delete(id);
	}
}
